import pika_lvgl as lv
import PikaStdLib as lib


class ColumnStyle(lv.style_t):
    def __init__(self):
        super().__init__()
        self.init()
        self.set_flex_flow(lv.FLEX_FLOW.ROW)
        self.set_width(300)
        self.set_height(100)


class Column(lv.obj):
    def __init__(self, parent):
        super().__init__(parent)
        self.align(lv.ALIGN.CENTER, 0, 0)
        self.add_style(ColumnStyle(), 0)
        self.set_flex_align(
            lv.FLEX_ALIGN.CENTER,
            lv.FLEX_ALIGN.CENTER,
            lv.FLEX_ALIGN.CENTER
        )

class ButtonStyle(lv.style_t):
    def __init__(self):
        super().__init__()
        self.init()

class Button(lv.btn):
    def __init__(self, parent, text, onclick):
        super().__init__(parent)
        self.set_size(30, 30)
        label = lv.label(self)
        label.set_text(text)
        label.align(lv.ALIGN.CENTER, 0, 0)
        self.add_event_cb(onclick, lv.EVENT.CLICKED, None)
        self.add_style(ButtonStyle(), 0)

def onclick1(e):
    global num
    num -= 1
    text.set_text(str(num))

def onclick2(e):
    global num
    num += 1
    text.set_text(str(num))


column = Column(lv.scr_act())
btn1 = Button(column, "-", onclick1)
num = 0
text = lv.label(column)
text.set_text(str(num))
btn2 = Button(column, "+", onclick2)

print('mem used max:')
lib.MemChecker().max()
print('mem used now:')
lib.MemChecker().now()
